﻿using AutoMapper;
using MediatR;
using T_Rbac_APi.Application.Command.Rule;
using T_Rbac_Demain;
using T_Rbac_Rep.Interface;

namespace T_Rbac_APi.Application.CommandHandler.RuleHandler
{
    public class RuleUpdateHandler : IRequestHandler<RuleUpdateCommand, int>
    {
        private readonly IMapper mapper;
        private readonly IRuleInformation ruleInformation;

        public RuleUpdateHandler(IMapper mapper, IRuleInformation ruleInformation)
        {
            this.mapper = mapper;
            this.ruleInformation = ruleInformation;
        }

        public async Task<int> Handle(RuleUpdateCommand request, CancellationToken cancellationToken)
        {
            var list = mapper.Map<Rule>(request);
            return await ruleInformation.Update(list);
        }
    }
}
